using System;
using System.Data;
using System.Configuration;
using System.IO;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using Krystalware.SlickUpload;
using Krystalware.SlickUpload.Providers;
using Adge.Common;

namespace Adge.WebControls
{
    /// <summary>
    /// An <see cref="IUploadStreamProvider" /> that streams each file into its own .zip file.
    /// </summary>
    public class AdgeUploadStreamProvider : IFileNameGenerator
    {
        
        #region IUploadStreamProvider Members
        /*
        public Stream GetInputStream(UploadedFile file)
        {
            FileStream fileS = null;          

            try
            {
                string path = GetFilePath(file);

                fileS = File.OpenRead(path);                

                return fileS;
            }
            catch
            {
                if (fileS != null)
                    fileS.Dispose();                

                return null;
            }
        }

        public Stream GetOutputStream(UploadedFile file)
        {
            FileStream fileS = null;            

            try
            {
                string path = GetFilePath(file);

                fileS = File.OpenWrite(path);

                return fileS;
            }
            catch
            {
                if (fileS != null)
                    fileS.Dispose();                

                return null;
            }
        }

        public void RemoveOutput(UploadedFile file)
        {
            string path = GetFilePath(file);

            if (File.Exists(path))
                File.Delete(path);
        }
        */
        #endregion         

        #region IFileNameGenerator Members

        public string GenerateFileName(UploadedFile file)
        {
            string path = string.Concat(Utils.GetUploadFilePathPrefix(), Path.GetFileName(file.ClientName));
            
            return path;
        }

        #endregion
    }

    public class AdgeCoverUploadStreamProvider : IFileNameGenerator
    {
        #region IFileNameGenerator Members

        public string GenerateFileName(UploadedFile file)
        {
            string path = string.Concat(AdgeConfig.CoverImageSoragePhyPath, Path.GetFileName(file.ClientName));

            return path;
        }

        #endregion
    }
}
